<template>
  <div>
    <view class="weui-form">
      <view class="weui-form__control-area">
        <view class="weui-cells__group weui-cells__group_form">
          <view class="weui-cells weui-cells_form">
            <view class="weui-cell weui-cell_active">
              <view class="weui-cell__hd">
                <label class="weui-label">通知人</label>
              </view>
              <view class="weui-cell__bd">
                <text>
                  {{ this.noticeData.notifier }}
                </text>
              </view>
            </view>
            <view class="weui-cell weui-cell_active">
              <view class="weui-cell__hd"><label class="weui-label">班级</label></view>
              <view class="weui-cell__bd">
                <text v-if="messageId!=null">
                  {{ this.noticeData.classes }}
                </text>
                <input
                    v-else
                    v-model="this.noticeData.classes"
                    class="weui-input"
                    placeholder="填写通知班级"/>
              </view>
            </view>
            <view class="weui-cell weui-cell_active">
              <view class="weui-cell__hd">
                <label class="weui-label">时间</label>
              </view>
              <view class="weui-cell__bd">
                <text>
                  {{ this.noticeData.date }}
                </text>
              </view>
            </view>
            <view class="weui-cell weui-cell_active">
              <view class="weui-cell__hd">
                <label class="weui-label">通知</label>
              </view>
              <view class="weui-cell__bd">
                <text v-if="messageId!=null">
                  {{ this.noticeData.notice }}
                </text>
                <textarea
                    v-else
                    v-model="this.noticeData.notice"
                    class="weui-textarea"
                    placeholder="填写通知内容"/>
              </view>
            </view>
          </view>
        </view>
      </view>
      <view v-if="messageId == null" class="weui-form__opr-area">
        <a v-if="this.isDisabled" aria-role="button" class="weui-btn weui-btn_primary" disabled>确定</a>
        <a v-else aria-role="button" class="weui-btn weui-btn_primary"  @click="handleClick();this.isDisabled=true">确定</a>
      </view>
    </view>
  </div>
</template>

<script>
import request from "@/utils/request.js";

export default {
  name: "index",
  data() {
    return {
      messageId: null,
      noticeData: {}, //notifier,classes,date,notice
      isDisabled: false,
    }
  },

  created() {
    this.creat()
  },

  methods: {
    handleClick() {
      request.post('/wx_push/push_message', this.noticeData).then(res => {

      })
    },
    creat() {
      this.getQueryString('messageId');
      if(this.messageId == null){
        request.get('/wx_user/notifier/?openId=' + 'orXpu6eE-qhA0wpjf8zqqpZfuloE').then(res => {
          this.noticeData = res.data.data
          console.log(this.noticeData)
        })
      } else {
        request.get('/wx_push/getMessage/?messageId='+ this.messageId).then(res => {
          this.noticeData = res.data.data
          console.log(this.noticeData)
        })
      }
    },
    getQueryString(name) {
      const url_string = window.location.href;
      const url = new URL(url_string);
      this.messageId = url.searchParams.get(name);
      console.log(this.messageId);
      return url.searchParams.get(name);
    },
  }
}
</script>

<style scoped>

</style>